/**     
* @Title: UserRoleServiceImpl.java
* @Package me.springboot.security.service.impl 
* @Description: TODO
* @author weiwei 
* @date 2017/08/29
* @version V1.0     
*/
package me.springboot.security.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import me.springboot.core.AbstractService;
import me.springboot.security.dao.UserRoleMapper;
import me.springboot.security.model.UserRole;
import me.springboot.security.service.UserRoleService;
import tk.mybatis.mapper.entity.Condition;

/**
 * @ClassName: UserRoleService
 * @Description: TODO
 * @author weiwei
 * @date 2017/08/29
 */
@Service
@Transactional
public class UserRoleServiceImpl extends AbstractService<UserRole> implements UserRoleService {

	@Resource
	private UserRoleMapper userRoleMapper;

	@Override
	public UserRole findByUserId(Integer userId) {
		if (null != userId) {
			Condition condition = new Condition(me.springboot.security.model.User.class);
			condition.createCriteria().andEqualTo("userId", userId);
			List<UserRole> userRoles = findByCondition(condition);
			if (!CollectionUtils.isEmpty(userRoles)) {
				return userRoles.get(0);
			}
		}
		return null;
	}

}